<template>
  <div>
    <van-nav-bar
        title="我的积分"
        :left-arrow="true"
        @click-left="onClickLeft"
    />
    <!-- Header -->

    <!-- 签到区域 -->
    <div class="sign-in">
      <p>当前积分：{{ Integral.num }}</p>
      <button @click="signIn" v-if="isSignedIn">立即签到</button>
      <button @click="signIn" v-if="!isSignedIn">已签到</button>
    </div>
    <!-- 日历 -->
    <el-calendar style="height: 530px;" v-model="nowdate">
      <template
          slot="dateCell"
          slot-scope="{date, data}">
        <div style="width:100%;height: 100%;">
          <div v-for="item in activeday" style="width: 0;height: 0px;">
            <el-badge v-if="data.day == item.signinTime" value="√"></el-badge>
          </div>
          <div class="spandate">{{ data.day.split('-').slice(2).join('-') }}</div>
        </div>
      </template>
    </el-calendar>

  </div>
</template>
<script>
import {addSigninRecord, findIntegral} from "@/api/wode/user";
import Vue from "vue";

export default {
  data() {
    return {
      activeday: [],
      nowdate: new Date(),
      isSignedIn: true, // 是否已签到
      Integral: {}
    }
  },
  computed: {

  },
  created() {
    this.findIntegral()
  },
  methods: {
    onClickLeft(){
      this.$router.push('/wode')
    },
    findIntegral() {
      let token = localStorage.getItem("token")
      findIntegral(token).then(res => {
        this.Integral = res
        this.activeday = this.Integral.signinRecords
      })
    },
    signIn() {
      const today = new Date();
      let token = localStorage.getItem("token")
      addSigninRecord(today, token).then(res => {
        this.findIntegral()
        this.$message.success(res.message)
      }).catch(error => {
        this.$message(error.message)
      })
    },
    OneDate(){

    }
  }
}
</script>

<style>
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background-color: #f9f9f9;
}

/* 签到区域样式 */
.sign-in {
  text-align: center;
  margin-top: 20px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
}

.sign-in button {
  margin-top: 10px;
  padding: 10px 20px;
  background: #67c23a;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
}

.dayEL .el-button--small {
  border: none;
}

.dayEL .el-button {
  background: transparent;
}

.dayEL >>> .el-calendar-table .el-calendar-day {
  height: 70px;
}

.spandate {
  margin-top: 10px;
  position: relative;
  top: 10px;
  margin-left: 25px;
  font-weight: bold;
  font-size: 16px;
}


.messageIndex {
  z-index: 99999 !important;
}

</style>
